<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/_fragments :: head(~{::title})">
    <title>博客管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" th:href="@{/css/me.css}">
    <link rel="stylesheet" th:href="@{/lib/editormd/css/editormd.min.css}">



</head>

<body>
    <!--导航-->
    <nav class="ui inverted attached segment m-padding-tb-mini m-shadow-small">
        <div class="ui container"><!--表示一个容器-->
            <div class="ui inverted secondary stackable menu">
                <!--这个stackable使得适应手机端-->
                <h2 class="ui teal header item">管理后台</h2>
                <a href="#" th:href="@{/blogsa}" class="active m-item item m-mobile-hide" ><i class="home icon"></i>博客</a>
                <a href="#" th:href="@{/totype}" class="m-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
                <a href="#" th:href="@{/toTageaka}" class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
                <div class="right m-item m-mobile-hide menu">
                    <div class="ui dropdown item">
                        <div class="text">
                            <img class="ui avatar image" src="https://unsplash.it/100/100?image=1005"> RobinZ
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a href="#" th:href="@{/admin/logout}" class="item">注销</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
            <i class="sidebar icon"></i>
        </a>
    </nav>

    <div class="ui container">
        <div class="ui teal inverted attached pointing menu">
            <a href="#" th:href="@{/admin/blogs/input}" class="item">发布</a>
            <a href="#" th:href="@{/admin/blogs}" class="active item">列表</a>
        </div>
    </div>
    <!--中间内容-->
    <div class=" m-container-small m-padding-tb-big">
        <div class="ui container"><!--表示一个容器-->
            <!--查询表单-->
            <form th:action="@{/blogsa}" method="get" class="ui secondary teal segment form">
                <div class="inline fields">
                    <div class="field">
                        <input type="text" name="title" placeholder="标题">
                    </div>
                    <!--下拉菜单-->
                    <div class="field">
                        <div class="ui selection dropdown">
                            <input type="hidden" name="typeId">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div th:each="ty,type : ${aka}" class="item" th:data-value="${ty.id}" th:text="${ty.name}">错误日志</div>
                            </div>
                        </div>
                    </div>
                    <!--是否推荐-->
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="recommend" name="recommend">
                            <!--让文字和box相关联，使得点击文字也可以打勾-->
                            <label for="recommend">推荐</label>
                        </div>
                    </div>
                    <div class="field">
                        <button type="submit" id="search-btn" class="ui mini primary button"><i class="search icon"></i>搜索</button>
                    </div>
                </div>
            </form>


            <table th:fragment="blogList" class="ui compact teal table">
                <thead>
                    <tr>
                        <th></th>
                        <th>标题</th>
                        <th>类型</th>
                        <th>推荐</th>
                        <th>状态</th>
                        <th>更新时间</th>
                    </tr>
                </thead>
                <tbody>
                <tr th:each="blog, iterStat : ${page.getRecords()}">
                    <td th:text="${iterStat.count}">1</td>
                    <td th:text="${blog.title}">刻意练习清单</td>
                    <td th:text="${blog.name}">认知升级</td>
                    <td th:text="${blog.recommend} ? '是':'否'">是</td>
                    <td th:text="${blog.published} ? '发布':'草稿'">发布</td>
                    <td th:text="${#dates.format(blog.update_time,'yyyy-MM-dd')}">2020-3-02</td>
                    <td>
                        <a href="#" th:href="@{/toUpdateBlog(id=${blog.id})}" class="ui mini teal button">编辑</a>
                        <a href="#"  th:onclick="aka(this,[[${blog.id}]])"   class="ui mini red button">删除</a>
                    </td>
                </tr>
                </tbody>

                <tfoot>
                    <tr>
                        <th colspan="7">
                            <div class="ui mini floated pagination menu">
                                <div class="item"><a th:href="@{/blogsa(pageIndex=1,title=${title},typeId=${typeId})}">首页</a></div>
                                <div class="item"> <a th:href="@{/blogsa(pageIndex=${page.getCurrent()-1},title=${title},typeId=${typeId})}">上一页</a></div>
                                <div class="item"><a th:href="@{/blogsa(pageIndex=${page.getCurrent()+1},title=${title},typeId=${typeId})}" th:if="${page.getCurrent()}<${page.getPages()}">下一页</a></div>
                                <div class="item"><a th:href="@{/blogsa(pageIndex=${page.getPages()},title=${title},typeId=${typeId})}">末页</a></div>
                            </div>
                            <a th:href="@{/inputBlog}" class="ui mini right floated teal button">新增</a>

                        </th>
                    </tr>
                </tfoot>
            </table>

            <div class="ui segment m-inline-block">
                当前页数:[<b th:text="${page.current}"></b>/<b th:text="${page.getPages()}"></b>]&nbsp;
            </div>

            <div class="ui success message" >
                <i class="close icon"></i>
                <div class="header">提示：</div>
                <p th:text="${msg}">恭喜，操作成功！</p>
            </div>

        </div>
    </div>

    <br>
    <br>
    <!--底部脚本元素-->
    <footer class="ui inverted vertical segment m-padding-tb-massive">
        <div class="ui center aligned container">
            <div class="ui inverted divided stackable grid"><!--分成16份-->
                <div class="three wide column">
                    <div class="ui inverted link list">
                        <div class="item">
                            <img src="./static/images/wechat.png" th:src="@{images/wechat.png}" class="ui rounded image" alt="" style="width: 110px">
                        </div>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">用户故事（User Story）</a>
                        <a href="#" class="item">用户故事（User Story）</a>
                        <a href="#" class="item">用户故事（User Story）</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">联系我</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">Email: 498166439@qq.com</a>
                        <a href="#" class="item">QQ: 498166439</a>
                        <a href="#" class="item">Wechat: robinz1996</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">Blog</h4>
                    <p class="m-text-thin m-text-spaced m-opacity-mini">这是我的个人博客，会分享编程，刷题，思考相关任何内容，希望可以让大家一起WDNMD...</p>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p class="m-text-thin m-text-spaced m-opacity-mini">Copyright @ 2020 - 2021 RobinZ Designed By RobinZ</p>
        </div>
    </footer>

    <th:block th:replace="admin/_fragments :: script"></th:block>

    <script>
        $('.menu.toggle').click(function() {
            $('.m-item').toggleClass('m-mobile-hide');
        });

        $('.ui.dropdown').dropdown({
            on : 'hover'
        });

        //消息提示关闭初始化
        $('.message .close')
            .on('click', function () {
                $(this)
                    .closest('.message')
                    .transition('fade');
            });

    </script>

<script th:src="@{js/jquery-1.12.4.js}" type="text/javascript"></script>
<script type="text/javascript">
    function aka(obj,id) {
        $.get("delTo","id="+id,function () {
            $(obj).parents().remove("tr")
            alert("刪除成功")
        })
    }
</script>
</body>
</html>